using System.Collections.Generic;
using UnityEngine;

public class SeasonIntervalDisplay : MonoBehaviour
{
	public GameObject eventButtonPrefab;

	public GameObject table;

	public UILabel titleLabel;

	public UIWidget widgetPanel;

	public float paddingx = 3f;

	public float paddingy = 3f;

	public List<SeasonEventButton> eventButtons = new List<SeasonEventButton>();

	public void Init(SeasonDefinitions.SeasonInterval seasonInterval, CareerSeasonLayer seasonLayer)
	{
		UIWidget component = GetComponent<UIWidget>();
		base.gameObject.SetActive(true);
		string text = string.Empty;
		bool flag = seasonInterval.isBeforeCurrentInterval || (seasonInterval.isCurrentInterval && seasonInterval.isPlayedAllEvents);
		component.alpha = ((!flag) ? 1f : 0.5f);
		if (flag)
		{
			text = " - Finished";
		}
		else if (seasonInterval.isCurrentInterval)
		{
			text = " (Current)";
		}
		titleLabel.text = seasonInterval.intervalName + text;
		int num = 0;
		int num2 = 2;
		Vector3[] localCorners = widgetPanel.localCorners;
		Vector3 vector = localCorners[1] + widgetPanel.cachedTransform.localPosition;
		Debug.Log("Top Left " + vector);
		foreach (SeasonDefinitions.SeasonEvent item in seasonInterval.eventsForInterval)
		{
			if (num >= eventButtons.Count)
			{
				eventButtons.Add(NGUITools.AddChild(table, eventButtonPrefab).GetComponent<SeasonEventButton>());
			}
			SeasonEventButton seasonEventButton = eventButtons[num];
			seasonEventButton.Init(item, seasonInterval, seasonLayer);
			UIWidget component2 = seasonEventButton.GetComponent<UIWidget>();
			Vector2 localSize = component2.localSize;
			Vector3 localPosition = component2.cachedTransform.localPosition;
			localPosition.x = vector.x + ((float)(num % num2) + component2.pivotOffset.x) * localSize.x + (float)(num % num2 + 1) * paddingx;
			localPosition.y = vector.y - ((float)(num / num2) + component2.pivotOffset.y) * localSize.y - (float)(num / num2 + 1) * paddingy;
			component2.cachedTransform.localPosition = localPosition;
			num++;
		}
	}
}
